package com.bird.component.lang.util.paramcheck.customize

import com.bird.component.lang.util.paramcheck.CheckTrait
import com.bird.component.lang.util.paramcheck.ParameterCheckBuilder
import com.bird.component.lang.util.paramcheck.RichUtil.Companion.richCheckModelMap


internal interface CustomizeTrait: CheckTrait {
    /**
     * 自定义校验
     * @param tip 校验提示
     * @param value 校验值
     * @param passTest 校验通过方法
     */
    fun <T> CustomizeTrait.customize(
        value: T,
        passTest: (T) -> Boolean,
    ): CustomizeBuilder<T> {
        return CustomizeBuilder(value, passTest)
    }
}

class CustomizeBuilder<T>(private val value: T, private val passTest: (T) -> Boolean) {
    fun orTip(tip: String): ParameterCheckBuilder {
        return richCheckModelMap(
            "CUSTOMIZE_CHECK",
            CustomizeCheckBean(tip = tip, typedPassTest = passTest, value = value),
        ) { CustomizeCheckModel(mutableListOf()) }
    }
}